
#include "xsg_sp_cmd.hpp"
#include "xen_mmc_mng.hpp"
#include "xsg_sp_util.hpp"

static void build_dft_xsg_cmd(command_manager_if_ptr cmdmng);

static void build_st_cmd(command_manager_if_ptr cmdmng);
static void build_osp_cmd(command_manager_if_ptr cmdmng);
static void build_dsp_cmd(command_manager_if_ptr cmdmng);
static void build_lks_cmd(command_manager_if_ptr cmdmng);
static void build_slk_cmd(command_manager_if_ptr cmdmng);
static void build_srte_cmd(command_manager_if_ptr cmdmng);
static void build_asp_cmd(command_manager_if_ptr cmdmng);
static void build_as_cmd(command_manager_if_ptr cmdmng);
static void build_bind_as_asp_cmd(command_manager_if_ptr cmdmng);
static void build_etc_cmd(command_manager_if_ptr cmdmng);


int xsg_crte_st(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_del_st(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_st(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_crte_osp(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_del_osp(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_osp(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_crte_dsp(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_del_dsp(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_dsp(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_ctrl_lks(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_lks(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_ctrl_srte(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_srte(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_crte_slk(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_del_slk(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_slk(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_cfg_slk(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_crte_asp(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_del_asp(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_asp(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_crte_as(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_del_as(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_as(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_bind_as(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_unbind_as(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_chg_mode(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_asp_add_addr(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_asp_del_addr(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_asp_addr(vty_ptr vty, const std::string& command, string_vector& opts);

int xsg_show_sgp(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_del_qos_class(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_crte_qos_class(vty_ptr vty, const std::string& command, string_vector& opts);
int xsg_show_qos_class(vty_ptr vty, const std::string& command, string_vector& opts);


int test_dialog(vty_ptr vty, const std::string& command, string_vector& opts);
int fixme_end_function(vty_ptr vty, const std::string& command, string_vector& opts);
int tst_exec_func(vty_ptr vty, const std::string& command, string_vector& opts);


int test_dialog_func(vty_ptr vty, const std::string inputline);


void build_xsg_sp_cmd(command_manager_if_ptr cmdmng)
{
	build_dft_xsg_cmd(cmdmng);
	build_st_cmd(cmdmng);
	build_osp_cmd(cmdmng);
	build_dsp_cmd(cmdmng);
	build_lks_cmd(cmdmng);
	build_slk_cmd(cmdmng);
	build_srte_cmd(cmdmng);
	build_asp_cmd(cmdmng);
	build_as_cmd(cmdmng);
	build_bind_as_asp_cmd(cmdmng);
	build_etc_cmd(cmdmng);
}

static void build_dft_xsg_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_mode(XSG_MODE_STR, "(xener)#");

	cmdmng->add_command(EXEC_MODE_STR, "configure xsg",
			CONFIG_HELP XSG_HELP, xsg_chg_mode);
	cmdmng->add_command(XSG_MODE_STR, "end",
			END_HELP, fixme_end_function);

	cmdmng->add_command(VIEW_MODE_STR, "test agent dialog", 
			TEST_HELP "vty agent\n" "daialog function\n", test_dialog);
};

static void build_st_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "st <0-63>"
			, CRTE_ST_HELP ST_NUM_HELP , xsg_crte_st);
	cmdmng->add_command(XSG_MODE_STR, "st <0-63> type (mtp2|m2pa) "	/* FIXME */
			, CRTE_ST_HELP  ST_NUM_HELP ST_TYPE_HELP MTP2_HELP M2PA_HELP
			, xsg_crte_st);

	cmdmng->add_command(XSG_MODE_STR, "no st <0-63>"
			, NO_HELP DEL_ST_HELP  ST_NUM_HELP , xsg_del_st);

	cmdmng->add_command(XSG_MODE_STR, "show st"
			, DIS_ST_HELP  ST_NUM_HELP , xsg_show_st);
}

static void build_osp_cmd(command_manager_if_ptr cmdmng)
{

	cmdmng->add_command(XSG_MODE_STR, "osp <0x1-0xFFFFFF> OPSN",
			 CRTE_OSP_HELP OPC_HELP OSPN_HELP, xsg_crte_osp);
	
	cmdmng->add_command(XSG_MODE_STR, "osp <0x1-0xFFFFFF> OPSN ni (int|rsv|nat|loc)",
			 CRTE_OSP_HELP OPC_HELP OSPN_HELP
			 NI_HELP SP_INT_HELP SP_RSV_HELP SP_NAT_HELP SP_LOC_HELP
			 ,xsg_crte_osp);

	cmdmng->add_command(XSG_MODE_STR, "osp <0x1-0xFFFFFF> OPSN ni (int|rsv|nat|loc)"
			" variant (unkown|itu_blue|itu_white|itu_china|ttc|jtt|ansi_88|ansi_91|ansi_96)"
			,CRTE_OSP_HELP OPC_HELP OSPN_HELP
			 NI_HELP SP_INT_HELP SP_RSV_HELP SP_NAT_HELP SP_LOC_HELP
			 MTP3_VARIANT_HELP UNKNOWN_HELP ITU_BLUE_HELP ITU_WHITE_HELP ITU_CHINA_HELP TTC_HELP JTT_HELP
			 ANSI_88_HELP ANSI_91_HELP ANSI_96_HELP
			 ,xsg_crte_osp);
	cmdmng->add_command(XSG_MODE_STR, "osp <0x1-0xFFFFFF> OPSN ni (int|rsv|nat|loc) "
			" variant (unkown|itu_blue|itu_white|itu_china|ttc|jtt|ansi_88|ansi_91|ansi_96)"
			" type (sep|stp)",
			CRTE_OSP_HELP OPC_HELP OSPN_HELP
			NI_HELP SP_INT_HELP SP_RSV_HELP SP_NAT_HELP SP_LOC_HELP
			MTP3_VARIANT_HELP 
			UNKNOWN_HELP ITU_BLUE_HELP ITU_WHITE_HELP ITU_CHINA_HELP TTC_HELP JTT_HELP
			ANSI_88_HELP ANSI_91_HELP ANSI_96_HELP
			SP_TYPE_HELP SEP_HELP STP_HELP
			,xsg_crte_osp);

	cmdmng->add_command(XSG_MODE_STR, "no osp <0x1-0xFFFFFF> OSPN",
			NO_HELP DEL_OSP_HELP OPC_HELP OSPN_HELP, xsg_del_osp);

	cmdmng->add_command(VIEW_MODE_STR, "show xsg osp",
			SHOW_HELP XSG_HELP DIS_SLK_HELP, xsg_show_osp);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg osp",
			SHOW_HELP XSG_HELP DIS_SLK_HELP, xsg_show_osp);
	cmdmng->add_command(XSG_MODE_STR, "show osp",
			SHOW_HELP DIS_SLK_HELP, xsg_show_osp);
}

static void build_dsp_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "dsp OSPN <0x1-0xFFFFFF> DSPN"
			,CRTE_DSP_HELP OSPN_HELP DPC_HELP DSPN_HELP ,xsg_crte_dsp);
	cmdmng->add_command(XSG_MODE_STR, "dsp OSPN <0x1-0xFFFFFF> DSPN loop"
			,CRTE_DSP_HELP OSPN_HELP DPC_HELP DSPN_HELP DSP_LOOP_HELP
			,xsg_crte_dsp);
	cmdmng->add_command(XSG_MODE_STR, "dsp OSPN <0x1-0xFFFFFF> DSPN type (ipsp|alias)"
			,CRTE_DSP_HELP OSPN_HELP DPC_HELP DSPN_HELP 
			DSP_TYPE_HELP DSP_IPSP_HELP DSP_ALIAS_HELP
			,xsg_crte_dsp);
	cmdmng->add_command(XSG_MODE_STR, "dsp OSPN <0x1-0xFFFFFF> DSPN loop type (ipsp|alias)"
			,CRTE_DSP_HELP OSPN_HELP DPC_HELP DSPN_HELP DSP_LOOP_HELP
			DSP_TYPE_HELP DSP_IPSP_HELP DSP_ALIAS_HELP
			,xsg_crte_dsp);

	cmdmng->add_command(XSG_MODE_STR, "no dsp OSPN DSPN <0x1-0xFFFFFF>"
			,NO_HELP DEL_DSP_HELP OSPN_HELP DSPN_HELP DPC_HELP
			,xsg_del_dsp);

	cmdmng->add_command(VIEW_MODE_STR, "show xsg dsp",
			SHOW_HELP XSG_HELP DIS_DSP_HELP, xsg_show_dsp);
	cmdmng->add_command(VIEW_MODE_STR, "show xsg dsp OSPN",
			SHOW_HELP XSG_HELP DIS_DSP_HELP OSPN_HELP, xsg_show_dsp);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg dsp",
			SHOW_HELP XSG_HELP DIS_DSP_HELP, xsg_show_dsp);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg dsp OSPN",
			SHOW_HELP XSG_HELP DIS_DSP_HELP OSPN_HELP , xsg_show_dsp);
	cmdmng->add_command(XSG_MODE_STR, "show dsp",
			SHOW_HELP DIS_DSP_HELP, xsg_show_dsp);
	cmdmng->add_command(XSG_MODE_STR, "show dsp OSPN",
			SHOW_HELP DIS_DSP_HELP OSPN_HELP, xsg_show_dsp);
}

static void build_lks_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "lks OSPN ASPN",
			CRTE_LKS_HELP OSPN_HELP ASPN_HELP, xsg_ctrl_lks);
	cmdmng->add_command(XSG_MODE_STR, "no lks OSPN ASPN",
			NO_HELP DEL_LKS_HELP OSPN_HELP ASPN_HELP, xsg_ctrl_lks);

	cmdmng->add_command(VIEW_MODE_STR, "show xsg lks",
			SHOW_HELP XSG_HELP DIS_LKS_HELP , xsg_show_lks);
	cmdmng->add_command(VIEW_MODE_STR, "show xsg lks OSPN",
			SHOW_HELP XSG_HELP DIS_LKS_HELP OSPN_HELP, xsg_show_lks);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg lks",
			SHOW_HELP XSG_HELP DIS_LKS_HELP , xsg_show_lks);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg lks OSPN",
			SHOW_HELP XSG_HELP DIS_LKS_HELP OSPN_HELP, xsg_show_lks);
	cmdmng->add_command(XSG_MODE_STR, "show lks",
			SHOW_HELP DIS_LKS_HELP , xsg_show_lks);
	cmdmng->add_command(XSG_MODE_STR, "show lks OSPN",
			SHOW_HELP DIS_LKS_HELP OSPN_HELP, xsg_show_lks);
	return ;
}

static void build_srte_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "srte OSPN DSPN ASPN <1-4>",
			CRTE_SRTE_HELP OSPN_HELP DSPN_HELP ASPN_HELP SR_PRIO_HELP
			, xsg_ctrl_srte);
	cmdmng->add_command(XSG_MODE_STR, "no srte OSPN DSPN ASPN",
			NO_HELP DEL_SRTE_HELP OSPN_HELP DSPN_HELP ASPN_HELP, xsg_ctrl_srte);

	cmdmng->add_command(VIEW_MODE_STR, "show xsg srte",
			SHOW_HELP XSG_HELP DIS_SRTE_HELP , xsg_show_srte);
	cmdmng->add_command(VIEW_MODE_STR, "show xsg srte OSPN",
			SHOW_HELP XSG_HELP DIS_SRTE_HELP OSPN_HELP, xsg_show_srte);
	cmdmng->add_command(VIEW_MODE_STR, "show xsg srte OSPN DSPN",
			SHOW_HELP XSG_HELP DIS_SRTE_HELP OSPN_HELP DSPN_HELP , xsg_show_srte);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg srte",
			SHOW_HELP XSG_HELP DIS_SRTE_HELP , xsg_show_srte);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg srte OSPN",
			SHOW_HELP XSG_HELP DIS_SRTE_HELP OSPN_HELP, xsg_show_srte);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg srte OSPN DSPN",
			SHOW_HELP XSG_HELP DIS_SRTE_HELP OSPN_HELP DSPN_HELP , xsg_show_srte);
	cmdmng->add_command(XSG_MODE_STR, "show srte",
			SHOW_HELP DIS_SRTE_HELP , xsg_show_srte);
	cmdmng->add_command(XSG_MODE_STR, "show srte OSPN",
			SHOW_HELP DIS_SRTE_HELP OSPN_HELP, xsg_show_srte);
	cmdmng->add_command(XSG_MODE_STR, "show srte OSPN DSPN",
			SHOW_HELP DIS_SRTE_HELP OSPN_HELP DSPN_HELP , xsg_show_srte);
	return ;
}


static void build_slk_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "slk OSPN ASPN <0-15> <0-63> <0-3> <1-31>",
			 CRTE_SLK_HELP OSPN_HELP ASPN_HELP SLC_HEP ST_HELP TRK_HELP TS_HELP,
			xsg_crte_slk);
	cmdmng->add_command(XSG_MODE_STR, "no slk OSPN ASPN <0-15>",
			NO_HELP DEL_SLK_HELP OSPN_HELP ASPN_HELP SLC_HEP,
			xsg_del_slk);

	bool ret = cmdmng->add_command(XSG_MODE_STR, "slk OSPN ASPN <0-15> stat (act|inact|inh|uninh|test)"
			,CRTE_SLK_HELP OSPN_HELP ASPN_HELP SLC_HEP
			"Change Status Action\n" "act\n" "inact\n" "inhibit\n" "uninhibit\n" "test\n"
			,xsg_cfg_slk);
	PDBG("!!!>>>>>> ret %s\n", (ret == true) ? "true" : "false");

	cmdmng->add_command(VIEW_MODE_STR, "show xsg slk",
			SHOW_HELP XSG_HELP DIS_SLK_HELP,
			xsg_show_slk);
	cmdmng->add_command(VIEW_MODE_STR, "show xsg slk OSPN",
			SHOW_HELP XSG_HELP DIS_SLK_HELP OSPN_HELP,
			xsg_show_slk);
	cmdmng->add_command(VIEW_MODE_STR, "show xsg slk OSPN ASPN",
			SHOW_HELP XSG_HELP DIS_SLK_HELP OSPN_HELP ASPN_HELP,
			xsg_show_slk);

	cmdmng->add_command(EXEC_MODE_STR, "show xsg slk",
			SHOW_HELP XSG_HELP DIS_SLK_HELP,
			xsg_show_slk);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg slk OSPN",
			SHOW_HELP XSG_HELP DIS_SLK_HELP OSPN_HELP,
			xsg_show_slk);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg slk OSPN ASPN",
			SHOW_HELP XSG_HELP DIS_SLK_HELP OSPN_HELP ASPN_HELP,
			xsg_show_slk);

	cmdmng->add_command(XSG_MODE_STR, "show slk",
			SHOW_HELP DIS_SLK_HELP, xsg_show_slk);
	cmdmng->add_command(XSG_MODE_STR, "show slk OSPN",
			SHOW_HELP DIS_SLK_HELP OSPN_HELP,
			xsg_show_slk);
	cmdmng->add_command(XSG_MODE_STR, "show slk OSPN ASPN",
			SHOW_HELP DIS_SLK_HELP OSPN_HELP ASPN_HELP,
			xsg_show_slk);

}

static void build_asp_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "no asp <1-65535>"
			,NO_HELP DEL_ASP_HELP ASP_ID_HELP 
			,xsg_del_asp);
	cmdmng->add_command(XSG_MODE_STR, "asp <1-65535> A.B.C.D"
			,CRTE_ASP_HELP ASP_ID_HELP ASP_P_IP_HELP 
			,xsg_crte_asp);
	cmdmng->add_command(XSG_MODE_STR, "asp <1-65535> A.B.C.D <1-65535>"
			,CRTE_ASP_HELP ASP_ID_HELP ASP_P_IP_HELP  PORT_NUM_HELP 
			,xsg_crte_asp);
	cmdmng->add_command(XSG_MODE_STR, "asp <1-65535> A.B.C.D <1-65535> <0-7>"
			,CRTE_ASP_HELP ASP_ID_HELP ASP_P_IP_HELP  PORT_NUM_HELP QOS_NUM_HELP
			,xsg_crte_asp);
	cmdmng->add_command(XSG_MODE_STR, "asp <1-65535> A.B.C.D <1-65535> <0-7> (iua|m3ua|sua)"
			,CRTE_ASP_HELP ASP_ID_HELP ASP_P_IP_HELP  PORT_NUM_HELP QOS_NUM_HELP 
			"IUA\n" "M3UA\n" "SUA\n"
			,xsg_crte_asp);

	cmdmng->add_command(XSG_MODE_STR, "show asp"
			,SHOW_HELP DIS_ASP_HELP, xsg_show_asp);
	cmdmng->add_command(XSG_MODE_STR, "show asp (<1-65535>|iua|m3ua|sua)"
			,SHOW_HELP DIS_ASP_HELP ASP_ID_HELP 
			"IUA\n" "M3UA\n" "SUA\n"
			, xsg_show_asp);
	cmdmng->add_command(XSG_MODE_STR, "show asp <1-65535> (iua|m3ua|sua)"
			,SHOW_HELP DIS_ASP_HELP ASP_ID_HELP 
			"IUA\n" "M3UA\n" "SUA\n"
			, xsg_show_asp);
	cmdmng->add_command(XSG_MODE_STR, "show asp (iua|m3ua|sua) <1-65535>"
			,SHOW_HELP DIS_ASP_HELP
			"IUA\n" "M3UA\n" "SUA\n" ASP_ID_HELP 
			, xsg_show_asp);
}


static void build_as_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> OSPN DSPN"
			,CRTE_AS_HELP RTX_HELP OSPN_HELP DSPN_HELP
			,xsg_crte_as);
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> OSPN DSPN (oride|share|bcast)"
			,CRTE_AS_HELP RTX_HELP OSPN_HELP DSPN_HELP "odride mode\n" "share mode\n" "broadcast\n"
			,xsg_crte_as);
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> OSPN DSPN (oride|share|bcast)"
			,CRTE_AS_HELP RTX_HELP OSPN_HELP DSPN_HELP "odride mode\n" "share mode\n" "broadcast\n"
			,xsg_crte_as);
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> OSPN DSPN (oride|share|bcast) (sccp|isup)"
			,CRTE_AS_HELP RTX_HELP OSPN_HELP DSPN_HELP "odride mode\n" "share mode\n" "broadcast\n"
			"sccp\n" "isup\n"
			,xsg_crte_as);
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> OSPN DSPN (oride|share|bcast) (sccp|isup) <0-255>"
			,CRTE_AS_HELP RTX_HELP OSPN_HELP DSPN_HELP "odride mode\n" "share mode\n" "broadcast\n"
			"sccp\n" "isup\n" "subsystem number\n" 
			,xsg_crte_as);
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> OSPN DSPN (oride|share|bcast) (sccp|isup) <0-255>"
			"<0-16383> <0-16383>"
			,CRTE_AS_HELP RTX_HELP OSPN_HELP DSPN_HELP "odride mode\n" "share mode\n" "broadcast\n"
			"sccp\n" "isup\n" "subsystem number\n"  "cic begin\n" "cic end\n" 
			,xsg_crte_as);
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> OSPN DSPN (oride|share|bcast) (sccp|isup) <0-255>"
			"<0-16383> <0-16383> <0-7>"
			,CRTE_AS_HELP RTX_HELP OSPN_HELP DSPN_HELP "odride mode\n" "share mode\n" "broadcast\n"
			"sccp\n" "isup\n" "subsystem number\n"  "cic begin\n" "cic end\n" "QoS Class\n"
			,xsg_crte_as);

	cmdmng->add_command(XSG_MODE_STR, "no as <1-65535>",
			NO_HELP SHOW_HELP DIS_AS_HELP, xsg_del_as);

	cmdmng->add_command(VIEW_MODE_STR, "show xsg as",
			SHOW_HELP XSG_HELP DIS_AS_HELP, xsg_show_as);
	cmdmng->add_command(VIEW_MODE_STR, "show xsg as <1-65535>",
			SHOW_HELP XSG_HELP DIS_AS_HELP RTX_HELP, xsg_show_as);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg as",
			SHOW_HELP XSG_HELP DIS_AS_HELP, xsg_show_as);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg as <1-65535>",
			SHOW_HELP XSG_HELP DIS_AS_HELP RTX_HELP, xsg_show_as);
	cmdmng->add_command(XSG_MODE_STR, "show as",
			SHOW_HELP DIS_AS_HELP, xsg_show_as);
	cmdmng->add_command(XSG_MODE_STR, "show as <1-65535>",
			SHOW_HELP DIS_AS_HELP RTX_HELP, xsg_show_as);
	return;
}

static void build_bind_as_asp_cmd(command_manager_if_ptr cmdmng)
{
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> bind <1-65535>"
			,CRTE_AS_HELP AS_BIND_HELP RTX_HELP ASP_ID_HELP
			,xsg_bind_as);
	cmdmng->add_command(XSG_MODE_STR, "as <1-65535> bind <1-65535>  <0-7>"
			,CRTE_AS_HELP RTX_HELP ASP_ID_HELP "SGP IDENTIFIER\n"
			,xsg_bind_as);

	cmdmng->add_command(XSG_MODE_STR, "no as <1-65535> bind <1-65535>"
			,NO_HELP CRTE_AS_HELP RTX_HELP AS_BIND_HELP ASP_ID_HELP, xsg_unbind_as);
	cmdmng->add_command(XSG_MODE_STR, "no as <1-65535> bind <1-65535>  <0-7>"
			,NO_HELP CRTE_AS_HELP RTX_HELP AS_BIND_HELP ASP_ID_HELP "SGP IDENTIFIER\n"
			,xsg_unbind_as);
}

static void build_etc_cmd(command_manager_if_ptr cmdmng)
{

	cmdmng->add_command(XSG_MODE_STR, "no asp <1-65535> add X.X.X.X"
			, NO_HELP ASP_HELP ASP_ID_HELP "add\n" "ipv4 address\n" 
			, xsg_asp_del_addr);
	cmdmng->add_command(XSG_MODE_STR, "asp <1-65535> add X.X.X.X"
			, ASP_HELP ASP_ID_HELP "add\n" "ipv4 address\n" 
			, xsg_asp_add_addr);
	bool ret = cmdmng->add_command(XSG_MODE_STR, "show asp <1-65535> address"
			,SHOW_HELP ASP_HELP ASP_ID_HELP "ipv4 address\n"
			,xsg_show_asp_addr);
	PDBG("!!!>>>>>> ret %s\n", (ret == true) ? "true" : "false");

	cmdmng->add_command(VIEW_MODE_STR, "show xsg sgp"
			,SHOW_HELP XSG_HELP "Display SGP Information\n" ,xsg_show_sgp);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg sgp"
			,SHOW_HELP XSG_HELP "Display SGP Information\n" ,xsg_show_sgp);
	cmdmng->add_command(XSG_MODE_STR, "show sgp"
			,SHOW_HELP "Display SGP Information\n" ,xsg_show_sgp);

	cmdmng->add_command(XSG_MODE_STR, "no sctp qos <1-7>"
			,NO_HELP "sctp\n" "qos\n" "class id\n" , xsg_del_qos_class);

	cmdmng->add_command(VIEW_MODE_STR, "show xsg sctp qos"
			,SHOW_HELP XSG_HELP "sctp\n" "qos\n"  , xsg_show_qos_class);
	cmdmng->add_command(EXEC_MODE_STR, "show xsg sctp qos"
			,SHOW_HELP XSG_HELP "sctp\n" "qos\n"  , xsg_show_qos_class);
	cmdmng->add_command(XSG_MODE_STR, "show sctp qos"
			,SHOW_HELP "sctp\n" "qos\n"  , xsg_show_qos_class);

	cmdmng->add_command(XSG_MODE_STR, "sctp qos <1-7> precedence "
			" (routine|priority|immediate|flash|flash_override|critic_ecp|internetwork_ctrl|network_ctrl) "
			" min_delay (normal|low) "
			" max_throughput (normal|high) "
			" max_reliablilty (normal|high) "
			" min_monetrary_cost (normal|minimize) "
			,"sctp\n" "qos\n" "class id\n" "PRECEDENCE\n" 
			"routine\npriority\nimmediate\nflash\nflash_override\ncritic_ecp\ninternetwork_ctrl\nnetwork_ctrl\n"
			"MINIMIZE DELAY\n" "normal\n" "low\n"
			"MAXIMIZE THROUGHPUT\n" "normal\n" "high\n"
			"MAXIMIZE RELIABLILTY\n" "normal\n" "high\n"
			"MINIMIZE MONETARY COST\n" "normal\n" "minimize\n"
			,xsg_crte_qos_class);
}

int xsg_show_sgp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	size = sprintf(buf, "DIS-SGP;\n");

	std::string tmp(buf, size);
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_show_asp_addr(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];

	size_t stpos=2;
	if (opts[1].compare("xsg") == 0) {
		opt_num -= 1; stpos=3;
	}
	size = sprintf(buf, "DIS-ASP-ADDR:%s;\n", opts[stpos].c_str());

	std::string tmp(buf, size);
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_asp_del_addr(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	size = sprintf(buf, "DEL-ASP-ADDR:%s, %s;\n", opts[1].c_str(), opts[3].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_asp_add_addr(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	size = sprintf(buf, "ADD-ASP-ADDR:%s, %s;\n", opts[1].c_str(), opts[3].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_show_qos_class(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	size = sprintf(buf, "DIS-QOS-CLS;\n");

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_del_qos_class(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	size = sprintf(buf, "DEL-QOS-CLS:%s;\n", opts[3].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_crte_qos_class(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	size = sprintf(buf, "CRTE-QOS-CLS:%s, %d, %d, %d, %d, %d;\n", opts[2].c_str()
			, change_qos_para(opts[4]), change_qos_nl(opts[6]), change_qos_nh(opts[8])
			, change_qos_nh(opts[10]), change_qos_nm(opts[12]));

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_show_spg(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	size = sprintf(buf, "DSI-SGP;\n");

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_bind_as(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	if (opt_num == 4) {
		size = sprintf(buf, "BIND-AS-ASP:%s,,%s;\n", opts[1].c_str(), opts[3].c_str());
	} else if (opt_num == 5) {
		size = sprintf(buf, "BIND-AS-ASP:%s,%s,%s;\n", opts[1].c_str(), 
				opts[4].c_str(), opts[3].c_str());
	} else {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_unbind_as(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;
	char cmdstr[256];
	
	if (opt_num == 5) {
		size = sprintf(buf, "UBND-AS-ASP:%s,,%s;\n", opts[2].c_str(), opts[4].c_str());
	} else if (opt_num == 6) {
		size = sprintf(buf, "UBND-AS-ASP:%s,%s,%s;\n", opts[2].c_str(), 
				opts[5].c_str(), opts[4].c_str());
	} else {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_crte_st(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;

	if (opt_num == 2) {
		size = sprintf(buf, "CRTE-ST:%s;\n", opts[1].c_str());
	} else if (opt_num == 4) {
		if (opts[3].compare("mtp2") == 0)
			size = sprintf(buf, "CRTE-ST:%s, 0;\n", opts[1].c_str());
		else if (opts[3].compare("m2pa") == 0)
			size = sprintf(buf, "CRTE-ST:%s, 1;\n", opts[1].c_str());
		else {
			vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
			return 0;
		}
	} else {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_del_st(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;

	size = sprintf(buf, "DEL-ST:%s;\n", opts[2].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_show_st(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
	size_t opt_num = opts.size(), size=0;;

	size = sprintf(buf, "DIS-ST;\n");

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_crte_osp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[1024];
    size_t opt_num = opts.size(), size=0;;
	int var = strtol(opts[1].c_str(), NULL, 16);
	PDBG("check var: %x %d\n", var, var);

	if (opt_num == 3) {
		size = sprintf(buf, "CRTE-OSP:,%d,%s;\n", var, opts[2].c_str());
	} 
	else if (opt_num == 5) {
		size = sprintf(buf, "CRTE-OSP:%d, %d, %s;\n", 
				change_ni(opts[4]), var, opts[2].c_str());
	} else if (opt_num == 7) {
		size = sprintf(buf, "CRTE-OSP:%d, %d, %s, %d;\n", 
				change_ni(opts[4]), var, opts[2].c_str(), change_mtp3_type(opts[6]));
	} else if (opt_num == 9) {
		size = sprintf(buf, "CRTE-OSP:%d, %d, %s, %d, %d;\n", 
				change_ni(opts[4]), var, opts[2].c_str(), 
				change_mtp3_type(opts[6]), change_sp_type(opts[8]));
	} 
	else {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}
	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_del_osp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;

	int var = strtol(opts[2].c_str(), NULL, 16);
	PDBG("check var: %x %d\n", var, var);
	if (opt_num == 4) {
		size = sprintf(buf, "DEL-OSP:%s,%d;\n", opts[3].c_str(), var);
	}
	else {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}
	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	PDBG("RECV DTA: %s\n", tmp.c_str());

	vty->output(tmp);
	return 0;
}

int xsg_show_osp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;

	size = sprintf(buf, "DIS-OSP;\n");
	
	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	PDBG("RECV DTA: %s\n", tmp.c_str());

	vty->output(tmp);

	return 0;
}


int xsg_crte_dsp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;

	int var = strtol(opts[2].c_str(), NULL, 16);
	PDBG("check var: %x %d\n", var, var);
	if (opt_num == 4) {
		size = sprintf(buf, "CRTE-SP:%s,%d,%s;\n", opts[1].c_str(), var, opts[3].c_str());
	} else if (opt_num == 5) {
		if (opts[4].compare("loop") == 0) {
			size = sprintf(buf, "CRTE-SP:%s,%d,%s,1;\n", opts[1].c_str(), var,
					opts[3].c_str());
		} else {
			vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		}
	} else if (opt_num == 6) {
		if (opts[5].compare("ipsp") == 0) {
			size = sprintf(buf, "CRTE-SP:%s,%d,%s,0,1;\n", opts[1].c_str(), var,
					opts[3].c_str());
		} else if (opts[5].compare("alias") == 0) {
			size = sprintf(buf, "CRTE-SP:%s,%d,%s,0,2;\n", opts[1].c_str(), var,
					opts[3].c_str());
		} else {
			vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		}
	} else if (opt_num == 7) { /* FIXME */
		if (opts[6].compare("ipsp") == 0) {
			size = sprintf(buf, "CRTE-SP:%s,%d,%s,1,1;\n", opts[1].c_str(), var,
					opts[3].c_str());
		} else if (opts[6].compare("alias") == 0) {
			size = sprintf(buf, "CRTE-SP:%s,%d,%s,1,2;\n", opts[1].c_str(), var,
					opts[3].c_str());
		} else {
			vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		}
	}
	else {
		vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}
	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_del_dsp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;

	if (opt_num == 5) {
		int var = strtol(opts[4].c_str(), NULL, 16);
		PDBG("check var: %x %d\n", var, var);
		size = sprintf(buf, "DEL-SP:%s,%s,%d;\n", opts[2].c_str(), 
				opts[3].c_str(), var);
	}
	else {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}
	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);
	vty->output(tmp);

	return 0;
}

int xsg_show_dsp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;
	string_vector cvt_opts;

	PDBG("opt_num: %d\n", opt_num);
	if (opts[1].compare("xsg") == 0) {
		cvt_opts.insert(cvt_opts.end(), opts.begin() + 3, opts.end());
	} else {
		cvt_opts.insert(cvt_opts.end(), opts.begin() + 2, opts.end());
	}

	opt_num = cvt_opts.size();
	if (opt_num == 0) { 
		size = sprintf(buf, "DIS-SP;\n");
	} else if (opt_num == 1) {
		size = sprintf(buf, "DIS-SP:%s;\n", cvt_opts[0].c_str());
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);

	return 0;
}


int xsg_ctrl_lks(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	if (opts[0].compare("no") == 0) {
		size = sprintf(buf, "DEL-LKS:%s,%s;\n",
				opts[2].c_str(), opts[3].c_str());
	} else {
		size = sprintf(buf, "CRTE-LKS:%s,%s;\n",
				opts[1].c_str(), opts[2].c_str());
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_show_lks(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;
	size_t stpos=2;

	if (opts[1].compare("xsg") == 0) {
		opt_num -= 1; stpos=3;
	}

	if (opt_num == 3) {
		size = sprintf(buf, "DIS-LKS:%s;\n", opts[stpos].c_str());
	} else {
		size = sprintf(buf, "DIS-LKS;\n");
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_ctrl_srte(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	if (opts[0].compare("no") == 0) {
		size = sprintf(buf, "DEL-SRTE:%s,%s,%s;\n",
				opts[2].c_str(), opts[3].c_str(), opts[4].c_str());
	} else {
		size = sprintf(buf, "CRTE-SRTE:%s,%s,%s,%s;\n",
				opts[1].c_str(), opts[2].c_str(), opts[3].c_str(), opts[4].c_str());
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_show_srte(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;
	size_t stpos=2;

	if (opts[1].compare("xsg") == 0) {
		opt_num -= 1; stpos=3;
	}
	if (opt_num == 4) {
		size = sprintf(buf, "DIS-SRTE:%s,%s;\n", opts[stpos].c_str(), opts[stpos+1].c_str());
	} else if (opt_num == 3) {
		size = sprintf(buf, "DIS-SRTE:%s;\n", opts[stpos].c_str());
	} else {
		size = sprintf(buf, "DIS-SRTE;\n");
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_crte_slk(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
    size_t opt_num = opts.size(), size=0;;

	if (opt_num != 7) {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}
	size = sprintf(buf, "CRTE-SLK:%s,%s,%s,%s,%s,%s;\n", 
			opts[1].c_str(), opts[2].c_str(), opts[3].c_str(), 
			opts[4].c_str(), opts[5].c_str(), opts[6].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	PDBG("RECV DTA: %s\n", tmp.c_str());

	vty->output(tmp);
	return 0;
}

int xsg_del_slk(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
    size_t opt_num = opts.size(), size=0;;

	if (opt_num < 4) {
        vty->output("$$ invailed args number!!%s", VTY_NEWLINE);
		return 0;
	}
	size = sprintf(buf, "DEL-SLK:%s,%s,%s;\n", 
			opts[2].c_str(), opts[3].c_str(), opts[4].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_show_slk(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
    size_t opt_num = opts.size(), size=0;;
	string_vector cvt_opts;

	PDBG("opt_num: %d\n", opt_num);
	if (opts[1].compare("xsg") == 0) {
		cvt_opts.insert(cvt_opts.end(), opts.begin() + 3, opts.end());
	} else {
		cvt_opts.insert(cvt_opts.end(), opts.begin() + 2, opts.end());
	}
	opt_num = cvt_opts.size();
	if (opt_num == 0) { 
		size = sprintf(buf, "DIS-SLK;\n");
	} else if (opt_num == 1) {
		size = sprintf(buf, "DIS-SLK:%s;\n", cvt_opts[0].c_str());
	} else if (opt_num == 2) {
		size = sprintf(buf, "DIS-SLK:%s,%s;\n", cvt_opts[0].c_str(), cvt_opts[1].c_str());
	} else {
        vty->output("$$ invailed args number(%d)!!%s", opt_num, VTY_NEWLINE);
		return 0;
    }

    std::string tmp(buf, size);
    PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);

    return 0;
};

int xsg_cfg_slk(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	size = sprintf(buf, "CHG-SLK-STS:%s,%s,%s,%d;\n", 
			opts[1].c_str(), opts[2].c_str(), opts[3].c_str(), 
			change_slk_action(opts[5].c_str()));

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);

	return 0;
}


int xsg_crte_asp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	if (opt_num == 3) {
		size = sprintf(buf, "CRTE-ASP:%s,,,%s;\n", opts[1].c_str(), opts[2].c_str());
	} else if (opt_num == 4) {
		size = sprintf(buf, "CRTE-ASP:%s,,%s,%s;\n", opts[1].c_str(), 
				opts[3].c_str(), opts[2].c_str());
	} else if (opt_num == 5) {
		size = sprintf(buf, "CRTE-ASP:%s,,%s,%s,%s;\n", opts[1].c_str(), 
				opts[3].c_str(), opts[2].c_str(), opts[4].c_str());
	} else if (opt_num == 6) {
		size = sprintf(buf, "CRTE-ASP:%s,%d,%s,%s,%s;\n", opts[1].c_str(), 
				change_uat_type(opts[5]), opts[3].c_str(), 
				opts[2].c_str(), opts[4].c_str());
	} else {
		return -1;
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_del_asp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	size = sprintf(buf, "DEL-ASP:%s;\n", opts[2].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_show_asp(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	if (opt_num == 2) {
		size = sprintf(buf, "DIS-ASP;\n");
	} else if (opt_num == 3) {
		int ret = change_uat_type(opts[2]);
		if (ret < 0) {
			size = sprintf(buf, "DIS-ASP:%s;\n", opts[2].c_str());
		} else {
			size = sprintf(buf, "DIS-ASP:,%d;\n", ret);
		}
	} else if (opt_num == 4) {
		int ret = change_uat_type(opts[2]);
		if (ret < 0) {
			size = sprintf(buf, "DIS-ASP:%s,%d;\n", opts[2].c_str(), 
					change_uat_type(opts[3]));
		} else {
			size = sprintf(buf, "DIS-ASP:%s,%d;\n", opts[3].c_str(), ret);
		}
	} else {
		return -1;
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}
	
int xsg_crte_as(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	if (opt_num == 4) {
		size = sprintf(buf, "CRTE-AS:%s,%s,%s;\n", opts[1].c_str(), opts[2].c_str(),
				opts[3].c_str());
	} else if (opt_num == 5) {
		size = sprintf(buf, "CRTE-AS:%s,%s,%s,%d;\n", opts[1].c_str(), opts[2].c_str(),
				opts[3].c_str(), change_as_mode(opts[4]));
	} else if (opt_num == 6) {
		size = sprintf(buf, "CRTE-AS:%s,%s,%s,%d,%d;\n", opts[1].c_str(), opts[2].c_str(),
				opts[3].c_str(), change_as_mode(opts[4]), change_ni_type(opts[5]));
	} 
	else if (opt_num == 7) {
		size = sprintf(buf, "CRTE-AS:%s,%s,%s,%d,%d,%s;\n", opts[1].c_str(), opts[2].c_str(),
				opts[3].c_str(), change_as_mode(opts[4]), change_ni_type(opts[5]),
				opts[6].c_str());
	} 
	else if (opt_num == 9) {
		size = sprintf(buf, "CRTE-AS:%s,%s,%s,%d,%d,%s,%s,%s;\n", opts[1].c_str(), opts[2].c_str(),
				opts[3].c_str(), change_as_mode(opts[4]), change_ni_type(opts[5]),
				opts[6].c_str(), opts[7].c_str(), opts[8].c_str());
	}
	else if (opt_num == 10) {
		size = sprintf(buf, "CRTE-AS:%s,%s,%s,%d,%d,%s,%s,%s,%s;\n", 
				opts[1].c_str(), opts[2].c_str(),
				opts[3].c_str(), change_as_mode(opts[4]), change_ni_type(opts[5]),
				opts[6].c_str(), opts[7].c_str(), opts[8].c_str(), 
				opts[9].c_str());
	}
	else {
		return -1;
	}

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_del_as(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;

	size = sprintf(buf, "DEL-AS:%s;\n", opts[2].c_str());

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int xsg_show_as(vty_ptr vty, const std::string& command, string_vector& opts)
{
	char buf[256];
	size_t opt_num = opts.size(), size=0;;
	size_t stpos=2;

	if (opts[1].compare("xsg") == 0) {
		opt_num -= 1; stpos=3;
	}

	if (opt_num == 2) 
		size = sprintf(buf, "DIS-AS;\n");
	else if (opt_num == 3)
		size = sprintf(buf, "DIS-AS:%s;\n", opts[stpos].c_str());
	else
		return -1;

	std::string tmp(buf, size);
	PDBG("cmd: %s\n", tmp.c_str());
	xen_mmc_mng::instance()->send_mmc(vty->id(), tmp);
	tmp.clear();
	xen_mmc_mng::instance()->recv_mmc(vty->id(), tmp);

	vty->output(tmp);
	return 0;
}

int test_dialog(vty_ptr vty, const std::string& command, string_vector& opts)
{
    vty->start_dialog(test_dialog_func);
    return 0;
};

int test_dialog_func(vty_ptr vty, const std::string inputline)
{
    if (inputline.compare("yes") == 0) {
        vty->output("your answer is %s%s", inputline.c_str(), VTY_NEWLINE);
        vty->stop_dialog();
    } else if (inputline.compare("no") == 0) {
        vty->output("your answer is %s%s", inputline.c_str(), VTY_NEWLINE);
        vty->stop_dialog();
    } else  {
        vty->output("do you wanna restart system? [No/yes]: ");
    }
    return 0;
}

int fixme_end_function(vty_ptr vty, const std::string& command, string_vector& opts)
{
    if (vty->change_mode(EXEC_MODE_STR) == false) {
        vty->output("$$ fail to change EXEC mode!!!%s", VTY_NEWLINE);
        return -1;
    };
    return 0;
}

int xsg_chg_mode(vty_ptr vty, const std::string& command, string_vector& opts)
{
    if (vty->change_mode(XSG_MODE_STR) == false) {
        vty->output("$$ fail to change XENER mode!!!%s", VTY_NEWLINE);
        return -1;
    };
    return 0;
};

int tst_exec_func(vty_ptr vty, const std::string& command, string_vector& opts)
{
    bool ret = true;
    std::string mode;

    ret = vty->is_auth_mode();
    mode = vty->current_mode();
    vty->output("current mode: %s, auth is %s%s\n",
            mode.c_str(),
            (ret == true) ? "ture" : "false",
            VTY_NEWLINE);
    
    vty->output("vty_id(%d), auth(%s), cur_mode(%s)%s",
            vty->id(), (vty->is_auth_mode() == true) ? "true" : "false",
            vty->current_mode().c_str(), VTY_NEWLINE);

    return 0;
};


